/**
 * 定义周报表模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.reportData.weekDataManager', ['water.apps.common.report.reportFormBase',
	                                                                          'water.common.dateUtil']);
	
	module.controller('reportDataWeekManagerController',function($scope,$monitorDataService,$controller,$dateUtil){

		var control = $controller("commonReportFormController",{$scope:$scope});
		/**
		 * 年选择下拉数据
		 */
		$scope.yearlist = [{name:'2016年',value:2016},{name:'2017年',value:2017}];
		/**
		 * 周下拉数据
		 */
		$scope.weekList;
		/**
		 * 选择的年
		 */
		$scope.selectYear
		/**
		 * 选择的周
		 */
		$scope.selectWeek;
		$scope.dataAPIName = 'getWeekReport';
		$scope.dataExportAPIName = "exportWeekExcel";
		
		/**
		 * 获取查询参数
		 */
		$scope.getQueryObject = function(){
			
			var weekInfo=$scope.selectWeek.split(",");
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":weekInfo[0] + " 00:00:00",
					"END": weekInfo[1] + " 23:59:59"
				};
			return queryObject;
		}
		/**
		 * 年选择事件
		 */
		$scope.onYearSelected = function(year){
			$scope.weekList = $dateUtil.getYearWeek(year);
			$scope.selectWeek= $scope.weekList[0].value;
			for(var i=0;i<$scope.weekList.length;i++){
				var week = $scope.weekList[i];
				if(week.today){
					$scope.selectWeek = week.value;
				}
			}
		}
		/**
		 * 周选择事件
		 */
		$scope.onWeekSelected = function(week){
			$scope.selectWeek = week;
			$scope.onSearchClick();
		}
		
		function _init(){
			var date = new Date();
			$scope.selectYear = date.getFullYear();
			$scope.onYearSelected($scope.selectYear);
		}
		
		_init();
		
	});
}(window, angular));